
package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.ServerBill;
import com.sasis.dao.ServerBillDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class ServerBillDaoiBatis extends BaseDaoiBATIS implements ServerBillDao {

    /**
     * @see com.sasis.dao.ServerBillDao#getServerBills(com.sasis.model.ServerBill)
     */
    public List getServerBills(final ServerBill serverBill) {
          return getSqlMapClientTemplate().queryForList("getServerBills", serverBill);
    }

    /**
     * @see com.sasis.dao.ServerBillDao#getServerBill(Integer id)
     */
    public ServerBill getServerBill(Integer id) {
        ServerBill serverBill = (ServerBill) getSqlMapClientTemplate().queryForObject("getServerBill", id);

        if (serverBill == null) {
            throw new ObjectRetrievalFailureException(ServerBill.class, id);
        }

        return serverBill;
    }

    /**
     * @see com.sasis.dao.ServerBillDao#saveServerBill(ServerBill serverBill)
     */    
    public void saveServerBill(final ServerBill serverBill) {
        Integer id = serverBill.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addServerBill", serverBill);
        } else {
            getSqlMapClientTemplate().update("updateServerBill", serverBill);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(ServerBill.class, id);
        }
    }

    /**
     * @see com.sasis.dao.ServerBillDao#removeServerBill(Integer id)
     */
    public void removeServerBill(Integer id) {
        getSqlMapClientTemplate().update("deleteServerBill", id);
    }
}
